package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.SysRoleMapper;
import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.entity.sys.SysRole;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Resource
    SysRoleMapper sysRoleMapper;
    @Override
    public PageInfo<SysRole> page(Integer pageNum, Integer pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        //执行查询：根据条件查询
        List<SysRole> sysRoleList = sysRoleMapper.findByRoleName(keyword);

        return new PageInfo<>(sysRoleList);
    }

    @Override
    public void deleteById(Long id) {
        sysRoleMapper.deleteById(id);
    }

    @Override
    public SysRole getById(Long id) {
        return sysRoleMapper.findById(id);
    }

    @Override
    public void updateById(SysRole sysRole) {
        sysRoleMapper.updateById(sysRole);
    }

    @Override
    public void save(SysRole sysRole) {
        sysRoleMapper.save(sysRole);
    }

    @Override
    public List<SysRole> findRolesAndIsChecked(Long userId) {
        //查询所有的角色， 然后根据userId查询该用户已分配的角色，最后设置所有角色列表中已分配的角色默认选中
        return sysRoleMapper.findRolesAndIsChecked(userId);
    }
}
